<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="webroot" value="${pageContext.request.contextPath}" />
<html lang="en">
<head>
<meta charset="utf-8">
<title>用户房产列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="${webroot}/static/layui/css/layui.css"
	media="all" />
<link rel="stylesheet" href="${webroot}/static/css/public.css"
	media="all" />
<style type="text/css">
.layui-btn+.layui-btn {
	margin-left: 0px;
}
.layui-form-label {
    width: 100px;
}
.layui-table td, .layui-table th {
    position: relative;
    padding: 9px 15px;
    min-height: 20px;
    line-height: 20px;
    font-size: 14px;
    text-align: center;
}
</style>
</head>
<body class="childrenBody">
	<form class="layui-form">
		<blockquote class="layui-elem-quote quoteBox">
			<form class="layui-form">
				<input type="hidden" id="staffValue" name="staffValue">
				<input type="hidden" id="userPay" name="userPay">
				<div class="layui-inline">
					<button type="button" class="layui-btn" id="test-upload-type1"><i class="layui-icon"></i>上传文件</button>
					<a class="layui-btn layui-btn-normal import_btn">确认导入</a>
					<a class="layui-btn layui-btn-danger export_btn">下载模版</a>
				</div>
			</form>
		</blockquote>
		<table class="layui-table">
		  <colgroup>
			  <col width="150">
			  <col width="200">
			  <col>
  		  </colgroup>
		  <thead>
		    <tr>
		      <th>名称</th>
		      <th>拼音</th>
		      <th>数量</th>
		      <th>长度</th>
		      <th>基数</th>
		      <th>拼音长度</th>
		    </tr> 
		  </thead>
		  <tbody id="userPayId">
		    
		  </tbody>
		</table>
	</form>
	<script type="text/javascript" src="${webroot}/static/layui/layui.js"></script>
	<script type="text/javascript" src="${webroot}/static/js/jquery-3.2.1.min.js"></script>
	<script>
		layui.use([ 'form', 'layer', 'laydate', 'table', 'laytpl','upload'],function() {
				var form = layui.form, layer = parent.layer === undefined ? layui.layer
				: top.layer, $ = layui.jquery, laydate = layui.laydate, laytpl = layui.laytpl, table = layui.table;
				upload = layui.upload;
				
				 upload.render({ //允许上传的文件后缀
				      elem: '#test-upload-type1'
				      ,url: '${webroot}/parameter/import'
				      ,accept: 'file' //普通文件
				      ,exts: 'xls|xlsx'
				      ,done: function(res){
				    	  if(res.success){
				    		  var list = res.content.list;
				    		  //console.log(JSON.stringify(list));
				    		  var str ="";
				    		  if(list.length > 0){
				    			  for (var i = 0; i < list.length; i++) {
				    				  str+='<tr>';
					    			  str+='<td>'+ list[i].word +'</td>';
					    			  str+='<td>'+ list[i].pinyin +'</td>';
					    			  str+='<td>'+ list[i].count +'</td>';
					    			  str+='<td>'+ list[i].length +'</td>';
					    			  str+='<td>'+ list[i].baseCount +'</td>';
					    			  str+='<td>'+ list[i].pinyinLength +'</td>';
					    			  str+='</tr>';
								  }
				    			  $("#userPayId").html(str);
				    		  }
				    		  $("#staffValue").val(JSON.stringify(list));
				    	  }
				      }
				    });
					
					$(".export_btn").click(function() {
						$(".export_btn").attr("disabled","disabled");
						 layer.confirm('确定到导出吗？', {
								icon : 3,
								title : '提示信息'
							}, function(index) {
								document.location.href="${webroot}/parameter/export";
								layer.close(index);
						 });
					})
					
					$(".import_btn").click(function() {
						if($("#staffValue").val() == ''){
							return top.layer.msg("请选择要导入的数据");
						}
						layer.confirm('确定要导入？', {
							icon : 3,
							title : '提示信息'
						}, function(index) {
							  $.post('${webroot}/parameter/insertall',{
								  staffValue : $("#staffValue").val()
						       },function(data){
						    	   var re=JSON.parse(data);
						        	 if(re.success){
						        		top.layer.close(index);
							  	        top.layer.msg("操作成功");
							  	      setTimeout(function(){window.parent.layer.closeAll();},2000);
						        	 }else{
						        		top.layer.msg(re.message);
						        	 }
						      })
						});
					})
					
					 function filterTime(val){
				        if(val < 10){
				            return "0" + val;
				        }else{
				            return val;
				        }
				    }
				    //定时发布
				   function fromDate(time){
				       time = new Date(time);
					   return time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());
				   }

		})
	</script>
</body>
</html>